package com.example.littleSpider.myapplication.activity;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.example.littleSpider.myapplication.R;
import com.example.littleSpider.myapplication.base.BaseActivity;
import com.example.littleSpider.myapplication.view.MyListView;
import com.example.littleSpider.myapplication.view.TitleView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 商品订单界面
 * Created by littleSpider on 2017/12/13.
 */

public class GoodsOrderActivity extends BaseActivity{

    @BindView(R.id.list_view)
    MyListView mListView;
    @BindView(R.id.et_remark)
    EditText et_remark;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_goods_order;
    }

    @Override
    protected void initView() {
        final MyAdapter myAdapter = new MyAdapter();
        mListView.setAdapter(myAdapter);
        mListView.setFocusable(false);
//        et_remark.setFocusable(false);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                myAdapter.setSelectedPosition(position);
                myAdapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.rl_choose_address)
    public void chooseAddress(){
        Intent intent = new Intent(this, ManageAddressActivity.class);
//        intent.putExtra("title", "");
        startActivity(intent);
    }

    @OnClick(R.id.rl_back)
    public void reBack(){
        finish();
    }

    class MyAdapter extends BaseAdapter{
        int selectedPosition = -1;

        public void setSelectedPosition(int position){
            selectedPosition = position;
        }

        @Override
        public int getCount() {
            return 4;
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = LayoutInflater.from(GoodsOrderActivity.this).inflate(R.layout.item_way_to_payment, null);
            ImageView iv_selected = (ImageView) convertView.findViewById(R.id.iv_selected);
            if (position == selectedPosition){
                iv_selected.setVisibility(View.VISIBLE);
            }else {
                iv_selected.setVisibility(View.GONE);
            }
            return convertView;
        }
    }
}
